import { defineStore } from "pinia";
import { store } from '/@/store';
import type { ErrorMessageMode } from '/#/axios';
import { GetDeptListModel } from '/@/api/sys/model/deptModel';
import { DeptApi } from '/@/api/sys/dept';


interface ClubState {
  deptList: any;
}

export const userClubStore = defineStore({
  id:'dept-club',
  state: (): ClubState => ({
    deptList: [],
  }),
  getters: {
    // getDeptList() {
    //   return this.deptList;
    // },
  },
  actions: {
    /**
     * @description: getDeptList
     */
     async getDeptList(
      params: {
        goHome?: boolean;
        mode?: ErrorMessageMode;
      },
    ): Promise<GetDeptListModel | null> {
      try {
        const { goHome = true, mode, ...deptParmas } = params;
        const data:any = await DeptApi(deptParmas, mode);
        console.log("DATA",data);
        return data;
        // save token
        // this.setToken(data);
        // return this.afterLoginAction(goHome);
      } catch (error) {
        return Promise.reject(error);
      }
    },
  }
})


export function useDeptStoreWithOut() {
  return userClubStore(store);
}